package com.acme.task1;

public class Calculator {
	public static void main(String[] args) {

		double operand1 = 0, operand2 = 0, result = 0;
        // XXX [MY] This name is not informative.
        //     [EP] "stringOperationFail" - ok?
		String errstr = null;
		
		//analyze number of arguments
		if (args.length != 3) {
			System.out.println("Wrong number of arguments.");
			return;
		}

		//get arguments
		try {
			operand1 = Double.parseDouble(args[0]);
			operand2 = Double.parseDouble(args[2]);
		}
		catch (NumberFormatException e) {
			System.out.println("Wrong operands.");
			return;
		}
		
		//analyze operation and make calculations
		switch (args[1].charAt(0)) {
		case '+':
			result = operand1 + operand2;
			break;
		case '-':
			result = operand1 - operand2;
			break;
		case '*':
			result = operand1 * operand2;
			break;
		case '/':
			if (operand2 != 0) {
				result = operand1 / operand2;
			}
			else {
				errstr = "Error: second operand is zero, division by zero.";
			}
			break;
		default:
            //XXX [MY] unknow -> unknown
            //    [PE] yep
			errstr = "Error: unknown operation.";
		}

		//print result at console like:
		if (errstr == null)
			System.out.println(args[0] + " " + args[1] + " " + args[2] + " = " + result);
		else 
			System.out.println(errstr);
			
	}
}
